let RoomMgr = function(opts){
    this.tables = new Map();
    this.interval = opts.time || 1000;
    this.gameId = opts.gameId || 1000;
    this.start();
};
RoomMgr.prototype.addTable = function(table){
    if(!table) return false;
    let tid = table.tid;
    if(!tid) return false;
    if(this.tables.has(tid)) return false;
    this.tables.set(tid,table);
    return true;
};
RoomMgr.prototype.delTable = function(table){
    if(!table.tid) return false;
    return this.tables.delete(table.tid);
};
RoomMgr.prototype.getTable = function(tid){
    
    return this.tables.get(tid);
};
RoomMgr.prototype.start = function(){
    setTimeout(()=>{
        this.update();
        this.start();
    },this.interval);
};
RoomMgr.prototype.update = function(){
    if(this.tables.size > 0){
        for(let table of this.tables.values()){
            if(table && table.update){
                table.update();
            }
        }
    }
};
module.exports = function(opts){
    console.log('opts---->',opts);
    if(!this._room_instance){
        this._room_instance = new RoomMgr(opts);
    };
    console.log('this._instance',this._room_instance);
    return this._room_instance;
};
